package com.ruoyi.web.controller.aimp;

import com.ruoyi.aimp.domain.Aimp_Behaviorwarn;
import com.ruoyi.aimp.service.IAimp_BehaviorwarnService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.common.utils.file.FileUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.ApiOperation;
import org.apache.tomcat.jni.FileInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;

/**
 * 行为告警Controller
 *
 * @author fengfeng
 * @date 2022-06-18
 */
@RestController
@RequestMapping("/ruoyi-aimp/behaviorwarn")
public class Aimp_BehaviorwarnController extends BaseController
{
    @Autowired
    private IAimp_BehaviorwarnService aimp_BehaviorwarnService;

    /**
     * 查询行为告警列表
     */
    @PreAuthorize("@ss.hasPermi('ruoyi-aimp:behaviorwarn:list')")
    @GetMapping("/list")
    public TableDataInfo list(Aimp_Behaviorwarn aimp_Behaviorwarn)
    {
        startPage();
        List<Aimp_Behaviorwarn> list = aimp_BehaviorwarnService.selectAimp_BehaviorwarnList(aimp_Behaviorwarn);
        return getDataTable(list);
    }



    /**
     * 导出行为告警列表
     */
    @PreAuthorize("@ss.hasPermi('ruoyi-aimp:behaviorwarn:export')")
    @Log(title = "行为告警", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Aimp_Behaviorwarn aimp_Behaviorwarn)
    {
        List<Aimp_Behaviorwarn> list = aimp_BehaviorwarnService.selectAimp_BehaviorwarnList(aimp_Behaviorwarn);
        ExcelUtil<Aimp_Behaviorwarn> util = new ExcelUtil<Aimp_Behaviorwarn>(Aimp_Behaviorwarn.class);
        util.exportExcel(response, list, "行为告警数据");
    }

    /**
     * 获取行为告警详细信息
     */
    @PreAuthorize("@ss.hasPermi('ruoyi-aimp:behaviorwarn:query')")
    @GetMapping(value = "/{behaviorwarnId}")
    public AjaxResult getInfo(@PathVariable("behaviorwarnId") Long behaviorwarnId)
    {
        return AjaxResult.success(aimp_BehaviorwarnService.selectAimp_BehaviorwarnByBehaviorwarnId(behaviorwarnId));
    }

    /**
     * 新增行为告警
     */
    @PreAuthorize("@ss.hasPermi('ruoyi-aimp:behaviorwarn:add')")
    @Log(title = "行为告警", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Aimp_Behaviorwarn aimp_Behaviorwarn)
    {
        return toAjax(aimp_BehaviorwarnService.insertAimp_Behaviorwarn(aimp_Behaviorwarn));
    }

    /**
     * 修改行为告警
     */
    @PreAuthorize("@ss.hasPermi('ruoyi-aimp:behaviorwarn:edit')")
    @Log(title = "行为告警", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Aimp_Behaviorwarn aimp_Behaviorwarn)
    {
        return toAjax(aimp_BehaviorwarnService.updateAimp_Behaviorwarn(aimp_Behaviorwarn));
    }

    /**
     * 删除行为告警
     */
    @PreAuthorize("@ss.hasPermi('ruoyi-aimp:behaviorwarn:remove')")
    @Log(title = "行为告警", businessType = BusinessType.DELETE)
	@DeleteMapping("/{behaviorwarnIds}")
    public AjaxResult remove(@PathVariable Long[] behaviorwarnIds)
    {
        return toAjax(aimp_BehaviorwarnService.deleteAimp_BehaviorwarnByBehaviorwarnIds(behaviorwarnIds));
    }

    /**
     * 检测图片上传
     */
    @PostMapping("/upLoadDetectionimg") //检测图片服务器路径
    public AjaxResult upLoadDetectionimg(@RequestParam("upLoadDetectionimgFile") MultipartFile file) throws IOException
    {
        if (!file.isEmpty()){
            //获取文件地址
            String avatar = FileUploadUtils.upload(RuoYiConfig.getUploadPath(), file);
            AjaxResult ajax = AjaxResult.success();
            ajax.put("DetectionimgUrl", avatar);
            return ajax;
        }
        return AjaxResult.error("上传图片异常，请联系管理员");
    }

    /**
     * 全景图片上传
     */
    @PostMapping("/upLoadPanoramaimg") //检测图片服务器路径
    public AjaxResult upLoadPanoramaimg(@RequestParam("upLoadPanoramaimgFile") MultipartFile file) throws IOException
    {
        if (!file.isEmpty()){
            //获取文件地址
            String avatar = FileUploadUtils.upload(RuoYiConfig.getUploadPath(), file);
            AjaxResult ajax = AjaxResult.success();
            ajax.put("PanoramaimgUrl", avatar);
            return ajax;
        }
        return AjaxResult.error("上传图片异常，请联系管理员");
    }


    /**
     * 视频上传
     */
    @PostMapping("/upLoadvideo")
    public AjaxResult upLoadvideo(@RequestParam("upLoadpicsFile") MultipartFile file) throws IOException
    {
        if (!file.isEmpty()){
            //获取文件地址
            String avatar = FileUploadUtils.upload(RuoYiConfig.getUploadPath(), file);
            AjaxResult ajax = AjaxResult.success();
            ajax.put("videoUrl", avatar);
            return ajax;
        }
        return AjaxResult.error("上传视频异常，请联系管理员");
    }
}
